package com.smartleanx.module.hrm.service.salary;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.smartleanx.module.hrm.dal.dataobject.dingDing.DingAttendanceTeam;
import com.smartleanx.module.hrm.dal.mysql.dingDing.DingAttendanceTeamMapper;
import com.smartleanx.module.hrm.service.examine.util.exception.ResultException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mybatis-plus
 * @since 2025-02-10
 */
@Service
public class HrmDeductionRuleServiceImpl implements HrmDeductionRuleService {
    @Autowired
    private DingAttendanceTeamMapper attendanceTeamMapper;

    @Override
    public PageInfo<DingAttendanceTeam> selectPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<DingAttendanceTeam> dingAttendanceTeams = attendanceTeamMapper.selectList(null);
        return new PageInfo<>(dingAttendanceTeams);
    }

    @Override
    public DingAttendanceTeam selectOne(Integer teamId) {
        DingAttendanceTeam dingAttendanceTeam = attendanceTeamMapper.selectById(teamId);
        if (ObjectUtils.isEmpty(dingAttendanceTeam)) {
            throw new ResultException("考勤信息不存在请刷新后重试");
        }
        return dingAttendanceTeam;
    }


    @Override
    public void updateDeductionRule(DingAttendanceTeam attendanceTeam) {
        if (attendanceTeam.getId() == null) {
            throw new ResultException("考勤组不能为空");
        }
        attendanceTeamMapper.updateById(attendanceTeam);
    }

}
